-- InvicibleAction
-- create by zouyb
-- 格挡动作

InvicibleAction = class("InvicibleAction", function()
    return ActionBase.create();
end);
function InvicibleAction.create(source, target)
    local self = InvicibleAction.new();
    self.source = source;
    self.target = target;

    return self;
end

-- 构造函数
function InvicibleAction:ctor()
end

-- 开始播放
function InvicibleAction:play()
    --播放特效
    local pos;
    local offset = cc.p(5, 0);
    if self.target ~= ME.user then
        pos = UIDungeonMgr:getCurLevel():getMonsterPos(self.target:getOwner());
        offset = cc.p(5, 33);
    else
        pos = UIDungeonMgr:getCurLevel():getHeroPos();
    end

    --飘字
    local icon = ccui.ImageView:create();
    icon:loadTexture("images/ui/common/invincible.png");
    icon:setPosition(cc.pAdd(pos, offset));
    icon:setScale(0.1);

    local function stopAction()
        UIDungeonMgr:getCurLevel():getEffectParent():removeChild(icon);
    end

    local callfunc = cc.CallFunc:create(stopAction)

    local scaleUp = cc.ScaleTo:create(0.12, 1.2);
    local scaleBack = cc.ScaleTo:create(0.09, 1.0);
    local delay = cc.DelayTime:create(0.2);
    local fadeOut = cc.FadeOut:create(0.2);
    icon:runAction(cc.Sequence:create(scaleUp, scaleBack, delay, fadeOut, callfunc));
    UIDungeonMgr:getCurLevel():getEffectParent():addChild(icon);
    AudioM.playFx("hit_miss");
    return 0;
end

return InvicibleAction;